/*
 * @Description: 
 * @Author: Jimmy
 * @Date: 2023-07-23 17:30:18
 * @LastEditTime: 2023-07-23 23:12:57
 * @LastEditors:  
 */

import { Context } from "koa"
//所有数据处理的结果函数
export const callbackData = (code: string = '1', message: string = '请求错误', data?: any) => {
    return {
        code,
        message,
        data: data || null
    }
}
// 错误处理的统一状态函数
export const errorHandler = async (err:any,ctx:Context)=>{
    let status = 500;
    switch(err.code){
        case '1':
            status = 400;
            break;
        case '2':
            status = 401;
        case '3':
            status = 402;
            break;
        case '999':
            status = 403;
            break;
        default:
            status = 500;
            break;
    }
    ctx.status = status;
    ctx.body = err;

}